package com.example.bidding.service;

import com.example.bidding.mapper.BorrowMapper;
import com.example.common.entity.PageParam;
import com.example.common.entity.ResponseCode;
import com.example.common.entity.Rsp;
import com.example.common.pojo.Borrow;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author 小许
 * @Title:
 * @Package
 * @Description:
 * @date 2020/11/21-17:18
 */
@Service
public class BidService {
    @Autowired
    private BorrowMapper borrowMapper;
    @Autowired
    private RedisServiceImpl redisService;

//    @Cacheable(value = "borrowList", key = "#p0")
    public Rsp getBid(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPageNo(), pageParam.getPageSize());
        List<Borrow> borrowList = borrowMapper.selectByTerm(pageParam);
        PageInfo<Borrow> pageInfo = new PageInfo<>(borrowList);
        if (StringUtils.isEmpty(pageInfo)) {
            return new Rsp(ResponseCode.ERROR, "访问失败");
        }
        return new Rsp(ResponseCode.SUCCESS, pageInfo, "访问成功");
    }

    public Rsp getByPrimaryKey(Integer id) {
        return new Rsp(ResponseCode.SUCCESS, borrowMapper.selectByPrimaryKey(id), "访问成功");
    }

}
